package mes.kanban.respository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import mes.kanban.entity.MesPermission;

/**
 * 权限
 * @author gjy
 *
 * 2018年2月11日下午3:02:35
 */
@Repository
public interface UserPermissionRespository extends BaseJpaRespository<MesPermission, String>{

	@Query(nativeQuery=true,
			value="select p.* from mes_permission p LEFT JOIN mes_role_permission rp ON rp.permission_id = p.id LEFT JOIN mes_role r ON rp.role_id = r.id where r.id in (:roleIds)")
	List<MesPermission> findPermissionByRoleId(@Param("roleIds") List<String> roleIds);
	

	@Query(nativeQuery=true,value="select p.* from mes_permission p LEFT JOIN mes_role_permission rp ON p.id = rp.permission_id LEFT JOIN mes_role r ON r.id = rp.role_id where rp.role_id = ?")
	List<MesPermission> getPermissionByRoleId(String roleId);


}
